


(async () => {
  var mongoose = require('mongoose');
  const Favorite = require('./schema/Favorite')
  const Product = require('./schema/Product')
  const User = require('./schema/User')
  // const axios = require('axios')
  mongoose.connect('mongodb://user1:123qwe@111.231.55.85:27017/order', { useNewUrlParser: true });
  var jwt = require('jsonwebtoken')
  const Message = require('./schema/Message')
  const config = require('./config')
  const crypto = require('crypto')
  // let orderNo = await OrderNo.findOneAndUpdate({ $inc: { id: 1 }})
  // let orderNo = await OrderNo.findOne()
  // await new OrderNo({ id: 11 }).save()
  // await new Product({
  //   sku: '001',
  //   title: 'Semir鞋子男板鞋2018秋冬新款休闲鞋韩版撞色男女布鞋情侣款潮鞋',
  //   season: 'summer',
  //   category: 'shoes',
  //   price: 119,
  //   sizes: ['35', '36', '37', '38', '39', '40', '41', '42', '43', '44'],
  //   colors: ['红白色调', '黑白色调'],
  //   group: 'hot',
  //   description: {
  //     text: '',
  //     imgSrc: [
  //       'https://img.alicdn.com/imgextra/i1/1077979376/O1CN01shlJ0v2J8G27JELuE_!!1077979376.jpg',
  //       'https://img.alicdn.com/imgextra/i1/1077979376/O1CN012dpRMC2J8G29rqctb_!!1077979376.jpg',
  //       'https://img.alicdn.com/imgextra/i4/1077979376/O1CN01GMaZrr2J8G2505yPa_!!1077979376.jpg',
  //       'https://img.alicdn.com/imgextra/i1/1077979376/O1CN01az3ACs2J8G2A4gVWs_!!1077979376.jpg',
  //     ]
  //   },
  //   thumbnail: 'https://img.alicdn.com/bao/uploaded/TB16M.3p29TBuNjy0FcL6TeiFXa_80x80.jpg',
  //   media: [
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i3/1077979376/O1CN01SoA66z2J8G31cOlTE_!!0-item_pic.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i1/1077979376/TB2ylL6o4WYBuNjy1zkXXXGGpXa_!!1077979376.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i1/1077979376/TB2yJXTqhSYBuNjSspjXXX73VXa_!!1077979376.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i4/1077979376/TB2o2.zeCMmBKNjSZTEXXasKpXa_!!1077979376.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://gdp.alicdn.com/imgextra/i4/1077979376/O1CN01O70aty2J8FzKqwz3K_!!1077979376.jpg'
  //     },
  //   ]
  // }).save()
  // await new Product({
  //   sku: '002',
  //   title: '2019新款夏季男士运动休闲韩版潮流潮鞋百搭透气布鞋跑步网面男鞋',
  //   season: 'summer',
  //   category: 'shoes',
  //   group: 'hot',
  //   price: 300,
  //   sizes: ['38', '39', '40', '41', '42', '43', '44', '45'],
  //   colors: ['黑金', '黑红', '黑白', '米白'],
  //   description: {
  //     text: '',
  //     imgSrc: [
  //       'https://img.alicdn.com/imgextra/i4/2948894599/O1CN01CJiOq01jqO1nLoOXO_!!2948894599.jpg',
  //       'https://img.alicdn.com/imgextra/i2/2948894599/TB2E8OJnN6I8KJjSszfXXaZVXXa_!!2948894599.jpg',
  //       'https://img.alicdn.com/imgextra/i2/2948894599/TB2E8OJnN6I8KJjSszfXXaZVXXa_!!2948894599.jpg',
  //       'https://img.alicdn.com/imgextra/i2/2948894599/TB2LChHgMFkpuFjSspnXXb4qFXa_!!2948894599.jpg'
  //     ]
  //   },
  //   thumbnail: 'https://img.alicdn.com/bao/uploaded/i3/2948894599/O1CN01KbMVmE1jqNzrEFLQd_!!2948894599.jpg_80x80.jpg',
  //   media: [
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i3/2948894599/TB2MJn8qXOWBuNjy0FiXXXFxVXa_!!2948894599-0-item_pic.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'video',
  //       src: 'https://tbm-auth.alicdn.com/9232tvDuyTZy8kgAUAn/TvlLFKbiMTNQTRuUTp3@@hd_hq.mp4?auth_key=1560395031-0-0-0a12c11e40b2a99b96a80f83aeb181a4'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i2/2948894599/TB1a0M_nH_I8KJjy1XaXXbsxpXa_!!0-item_pic.jpg_430x430q90.jpg'
  //     },
  //     {
  //       _type: 'img',
  //       src: 'https://img.alicdn.com/imgextra/i4/2948894599/TB2FswpEKySBuNjy1zdXXXPxFXa_!!2948894599.jpg_430x430q90.jpg'
  //     },
  //   ]
  // }).save()
  // let arr = []
  // for(let i = 0; i < 30; i ++) {
  //   arr.push({
  //     sku: '003',
  //     title: 'NIKE AIR FORCE 1 AF1 空军一号 男女板鞋315122-111-001 315115',
  //     season: 'all',
  //     category: 'shoes',
  //     group: 'other',
  //     price: 599,
  //     sizes: ['35.5', '36', '36.5', '37.5', '38', '38.5', '39', '40', '40.5', '41', '42', '43', '44', '44.5', '45', '46'],
  //     colors: ['白', '黑'],
  //     description: {
  //       text: '文本描述',
  //       imgSrc: [
  //         'https://img.alicdn.com/imgextra/i4/559933948/O1CN011f2E8IAfXEHY6d8_!!559933948.jpg',
  //         'https://img.alicdn.com/imgextra/i4/559933948/O1CN011f2E8IAfXEHY6d8_!!559933948.jpg',
  //         'https://img.alicdn.com/imgextra/i3/559933948/TB2kOkjdTTI8KJjSsphXXcFppXa_!!559933948.jpg',
  //       ]
  //     },
  //     thumbnail: 'https://img.alicdn.com/bao/uploaded/i3/2948894599/O1CN01KbMVmE1jqNzrEFLQd_!!2948894599.jpg_80x80.jpg',
  //     media: [
  //       {
  //         _type: 'img',
  //         src: 'https://img.alicdn.com/imgextra/i3/2948894599/TB2MJn8qXOWBuNjy0FiXXXFxVXa_!!2948894599-0-item_pic.jpg_430x430q90.jpg'
  //       },
  //       {
  //         _type: 'video',
  //         src: 'http://tbm-auth.alicdn.com/AuFfm5WQY6Pct1rnOyW/y6yNrzUuuQBQIijTWZo@@hd.mp4?auth_key=1560396371-0-0-95ab4a1b88cce92231da8a11de526700'
  //       },
  //     ]
  //   })
  // }
  // let user = await User.findOne({ loginUser: 'admin' });
  // console.log(user)
  // let searchText = '00';
  // let favorites = await Favorite.paginate({
  //   $or: [
  //     {
  //       'productId.title': new RegExp(searchText, 'i')
  //     },
  //     {
  //       'productId.sku': new RegExp(searchText, 'i')
  //     }
  //   ]
  // }, {
  //   populate: 'productId',
  //   offset: 0,
  //   limit: 20
  // })
  // console.log(favorites.docs[0])
  let favorites = await Favorite.find({
    opCode: '1003'
  }).populate('productId')
  console.log(favorites)
  // let products = await Product.paginate({
  //   'description.text': '文本描述'
  // }, {
  //   offset: 0,
  //   limit: 20
  // })
  // console.log(products.docs[0])
  // await Product.updateMany({}, { $set: {brand: '西村名物'} })
  // let products = await Product.paginate({ brand: '西村名物' }, { offset: '0', limit: 20 })
  process.exit(0)
})()
// await User.insertMany([
//   {
//     opCode: '1001',
//     opName: '周溢满',
//     loginUser: 'zhou',
//     password: 'ca1d64bbe9459e7864dec6dbb3a06f13',
//     area: '山西阳泉',
//     stores: [
//       {
//         store: '天利购物中心店',
//         brands: [ 'xxx' ],
//         address: '山西省阳泉市城区天利购物中心'
//       }
//     ]
//   },
//   {
//     opCode: '1002',
//     opName: '孙欢',
//     loginUser: 'sun',
//     password: 'ca1d64bbe9459e7864dec6dbb3a06f13',
//     area: '浙江桐庐',
//     stores: [
//       {
//         store: '高铁站店',
//         brands: [ 'w' ],
//         address: '浙江省杭州市桐庐县高铁站',
//       }
//     ]
//   },
//   {
//     opCode: '1003',
//     opName: '吴杭峰',
//     loginUser: 'wu',
//     password: 'ca1d64bbe9459e7864dec6dbb3a06f13',
//     area: '浙江绍兴',
//     stores: [
//       {
//         store: '袍江店',
//         brands: [ '西村名物', 'w' ],
//         address: '浙江省绍兴市袍江区',
//       },
//       {
//         store: '上虞店',
//         brands: [ 'w' ],
//         address: '浙江省绍兴市上虞区',
//       }
//     ]
//   },
// ])